package cn.hutool.core.util;

import java.util.Objects;
import java.util.function.BiConsumer;

/**
 * Iterable工具类
 *
 * @author Jianx
 * @since 5.7.18
 */
public class IterablesUtil {
	/**
	 * forEach带索引输出
	 *
	 * @param elements
	 * @param action
	 * @param <E>
	 */
	public static <E> void forEach(
			Iterable<? extends E> elements, BiConsumer<Integer, ? super E> action) {
		Objects.requireNonNull(elements);
		Objects.requireNonNull(action);

		int index = 0;
		for (E element : elements) {
			action.accept(index++, element);
		}
	}
}
